Skip to content

fix(json): recognize mixed-case JSON media types - #341

Open
yumingjs wants to merge 1 commit into
cloudevents:mainfrom
yumingjs:codex/json-media-type-case
Open

yumingjs wants to merge 1 commit into
cloudevents:mainfrom
yumingjs:codex/json-media-type-case

Conversation

@yumingjs

@yumingjs yumingjs commented Dec 2, 2026

Copy link
Copy Markdown

Fixes #340

A binary payload labeled Application/JSON comes back as a string. A structured event labeled Application/vnd.api+JSON; profile=Example similarly turns an object into a string when written.

Match JSON media types case-insensitively within ASCII in the core formatter. The original datacontenttype and its parameter values are preserved. This leaves binding mode detection and the v1 converters unchanged.

The regression cases exercise structured writes and binary reads. Both failed against the unmodified formatter.

  • Linux, Python 3.11.18, pytest tests — 891 passed, 18 expected failures.
  • Ruff import checks and pre-commit hooks on both changed files passed, including mypy. I used the repository's uv/pytest workflow. There is no tox configuration in this checkout.

Signed-off-by: Kong Liangyu <201232322+yumingjs@users.noreply.github.com>

@EmiRZx EmiRZx left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested binary HTTP reads and structured writes. Application/JSON and APPLICATION/VND.API+JSON bodies now decode to objects. Application/vnd.api+JSON; profile=Example and TEXT/JSON are written as JSON objects. re.ASCII keeps application/jſon out, as on main. the new tests fail on main.

one case still misses. application/json ; charset=utf-8 writes the data as a string because the pattern has no room for whitespace before ;. that could be a follow-up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Core JSONFormat treats mixed-case JSON media types as text

2 participants